function [sigmaVec, covMat, snr, snrVec, condNum, condNumVec...
    ] = computeerrbounds_network(Params, detNameVec, noisePSDVec, ...
    lambdaVec, projectOutDims)
%
% COMPUTEERRBOUNDS_NETWORK - compute the RMS errors in estimating the parameters
% of a coalescing binary using a netowrk of detectors, employing 3.5PN SPA waveforms 
% 
% usage: [sigmaVec, covMat, snr, snrVec, condNum, condNumVec...
%           ] = computeerrorbounds(Params, detNameVec, noisePSDVec, lambdaVec)
%
% P. Ajith, 8 Aug 2009
% 
% $Id: computeerrbounds_network.m 59 2010-01-20 21:41:01Z anand.sengupta $

    % compute the PN errors, if appropriate 
    [flso] = calcflso(Params.totalMass);

    if flso > Params.fLower

        if length(detNameVec) ~= length(noisePSDVec)
            error('### length(detNameVec) is not equal to length(noisePSDVec)');
        end

        % compute the fisher matrix for each detector
        for iDet=1:length(detNameVec)
        
            % load the detector tensor
            Params.Det = LoadDetectorData(detNameVec{iDet});

            % compute the fisher matrix
            fishMatDet = [];
            [fishMatDet, snrVec(iDet), AeffWeightdDet] = computefishermatrix_ifo(...
                Params, noisePSDVec{iDet}, lambdaVec);

            % condition number of the fisher matrix
            condNumVec(iDet) = cond(fishMatDet);

            if iDet == 1
                fishMat = fishMatDet;
                AeffWeightd = AeffWeightdDet; 
            else
                % sum the fisher matrices of the individual detectors
                fishMat = fishMat + fishMatDet;
    
                % sum the noise-weighted (fourier-domain) amplitude of the
                % signal at individual detectors -- in order to compute the 
                % network SNR
                AeffWeightd = AeffWeightd + AeffWeightdDet; 
            end
    
        end
            
        rankMat = rank(fishMat);

        % project out some dimensions if asked 
        [fishMat] = schurcomplement(fishMat, length(lambdaVec)-projectOutDims);

        condNum = cond(fishMat);

        % if the condition number is sufficiently small, invert the fisher matrix
        % to compute the covariance matrix. If not, fill the covariance matrix 
        % with zeros. 
        if condNum < 1e30
            covMat = inv(fishMat);
            %covMat = double(inverse(fishMat));
        else
            warning('condition number > 1e30. setting covariance matrix to zero');
            covMat = zeros(size(fishMat));
        end

        % compute the RMS errors from the diagonal elements of the 
        % covariance matrix
        sigmaVec = sqrt(diag(covMat));

        % compute the network SNR
        snr = 2*sqrt(sum(AeffWeightd.^2));

    else 
        warning('flso is greater than fLower');
        sigmaVec = [];
        covMat = [];
        snr = [];
        snrVec = []; 
        condNum = [];
        condNumVec = [];
    end


